﻿var _location = new Array();
var _bearing;

setInterval(timed, 1000);
function timed() {
    navigator.geolocation.getCurrentPosition(
    function (position) {
        _location = util.toECEF(position.coords.latitude, position.coords.longitude);
        _location[4] = position.coords.latitude;
        _location[5] = position.coords.longitude;
        if (!isSensorReady) init();
    },
    function (error) { alert('error'); },
    { maximumAge: 60000, timeout: 5000, enableHighAccuracy: false });
}

//if (navigator && navigator.geolocation) {
//        var watchID = navigator.geolocation.watchPosition(
//            function (position) {
//                _location = util.toECEF(position.coords.latitude, position.coords.longitude);
//                if(!isSensorReady) init();
//            }
//        );
//} else {
//    // No geo location support, set defaults.
//    _location[0] = 0;
//    _location[1] = 0;
//    _location[2] = 0;
//    if (!isSensorReady) init();
//}

if (window.DeviceOrientationEvent) {
    window.addEventListener("deviceorientation", function (e) {
        _bearing = 360 - e.alpha;
    }, false);
}